//app.js
var store = require('lib/store.js');
var util = require('utils/util.js');
App({
  appData:{},
  store:store,
  isFirst:false,
  setup:{
     lastLauncherTime:0,
     lastShowCollectId:'',
     lastShowType:0 //0：itemList 1:collectList
  },
  onLaunch: function () {
    var setup = this.store.getSetup();
    if (!setup) {
      this.isFirst = true;
    }
    else {
      this.setup = setup;
    }
    this.system = wx.getSystemInfoSync();
    this.checkSystem();
    console.log(this.system);
  },
  checkSystem: function() {
    var sys = this.system;
    var model = sys.model;
    this.rowGapBase = 12;
    this.extPaddingBase = 14;
    if (model.indexOf('iPhone') >= 0) {
        this.fontHeight = 21;
        this.rowGap = Math.floor(this.rowGapBase * 375 / sys.windowWidth);
        this.extPadding = Math.floor(this.extPaddingBase * 375 / sys.windowWidth);
        if (model.indexOf('iPhone 6 Plus') || model.indexOf('iPhone 6s Plus')) {
          //标准模式
          if (sys.windowWidth === 414) {
            this.extPadding--;
          }
        }
    }
    else {
        this.fontHeight = 21;
        this.rowGap = Math.floor(this.rowGapBase * 375 / sys.windowWidth);
        this.extPadding = Math.floor(this.extPaddingBase * 375 / sys.windowWidth);
    } 
    var fontH = util.rpx2px(this.fontHeight, sys.windowWidth);
    var paddingH = util.rpx2px(56, sys.windowWidth) - 2;

    this.checkBound = this.extPadding + fontH + paddingH;
    this.crossBound = -this.checkBound;
    console.log(this.checkBound);
    this.CREATE_ITEM_THRESHOLD = this.checkBound;
    this.SWITCH_THRESHOLD = this.checkBound * 2;
    this.ITEM_HEIGHT = this.checkBound;
    this.COLLECT_TEXT_WIDTH = sys.windowWidth - this.ITEM_HEIGHT - util.rpx2px(48, sys.windowWidth);
    this.UP_SORTMOVE_THRESHOLD = this.ITEM_HEIGHT * 0.5;
    this.DOWN_SORTMOVE_THRESHOLD = this.ITEM_HEIGHT * 2;
  },
  setSetup: function (collectId, showType) {
    this.setup.lastShowType = showType;
    this.setup.lastShowCollectId = collectId;
    this.store.saveSetup(this.setup);
  },
  getSetup: function () {
    return this.setup;
  },
  onError: function (msg) {
    console.log(msg);
  },
})